package com.example.ordersystem.controller;

import com.example.ordersystem.model.Goods;
import com.example.ordersystem.model.PageRequest;
import com.example.ordersystem.model.PageResult;
import com.example.ordersystem.service.GoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.xml.transform.Result;
import java.util.List;

/**
 * @className: GoodController
 * @author: 芃
 * @description: 商品请求控制器
 * @date: 2024/12/31 15:23
 */
@RestController
@RequestMapping("/good")
@Slf4j
public class GoodController {

    @Autowired
    private GoodService goodService;

    /**
     * @param goodName: 商品名称
     * @param goodPrice: 商品价格
     * @param goodNum: 商品库存
     * @return Boolean
     * @author: zyp19
     * @description:
     * @date: 2024/12/31 15:25
     */
    @RequestMapping("/addGood")
    public Boolean addGood(@RequestParam String goodName, @RequestParam Double goodPrice, @RequestParam Integer goodNum) {
        Integer result = goodService.addGood(goodName,goodPrice,goodNum);
        log.info("result = " + result);
        if (result > 0){
            return true;
        }else {
            return false;
        }
    }


    @RequestMapping("/getGoodsListByPage")
    public PageResult<Goods> getGoodsList(PageRequest pageRequest){
        if (pageRequest.getCurrentPage()<1){
            return null;
        }
        PageResult<Goods> goodsList = goodService.getListByPage(pageRequest);
        return goodsList;
    }


    @RequestMapping("/deleteByGoodId")
    public Boolean deleteByGoodId(Integer id){
        return goodService.deleteByGoodId(id);
    }
}
